package com.woniuxy.commons.service.factory;

import com.woniuxy.commons.entity.Goods;
import com.woniuxy.commons.service.ProviderService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;

/**
 * @Author zhangyong
 * @Date 2021/8/3 0003
 */
//工厂类：创建fallback方法
@Component //加入ioc容器
public class ProviderServiceFactory implements FallbackFactory<ProviderService> {

    @Override
    public ProviderService create(Throwable throwable) {
        //匿名内部类：其中的方法就是fallback方法
        return new ProviderService() {
            @Override
            public List<Goods> all() {
                List<Goods> goodsList = Arrays.asList(
                        new Goods(3001,"服务器正忙",100)
                );
                return goodsList;
            }

            @Override
            public Goods findById(int id) {
                return null;
            }

            @Override
            public Boolean add(Goods goods) {
                return null;
            }

            @Override
            public Boolean update(Goods goods) {
                return null;
            }

            @Override
            public void del(int id) {

            }
        };
    }
}
